<?php
//自动生成,请根据需要修改
namespace app\banner\controller;
use app\common\controller\Base;
use think\facade\Request;
use think\Db;
/**
* @title 图片分类表接口
* @description 图片分类表说明
* @group 首页
*/
class Category extends Base{

	/**
	* @title 按条件删除记录
	* @description 按条件删除图片分类表的数据
	* @author 开发者（zzz）
	* @url /banner/category/delete
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预留字段1
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前状态
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:sort type:VarChar require:1 default:0 other: desc:排序值
	* @param name:type_name type:VarChar require:1 default:0 other: desc:分类名
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	*
	* @return ext1:预留字段1
	* @return status:当前状态
	* @return updater:更新者
	* @return creater:创建者
	* @return sort:排序值
	* @return type_name:分类名
	* @return id:id
	*
	*/
	public function delete (){
		$input=input();
		//模块 - 输入数据
		$input['ext1'] = Request::post('ext1');
		$input['status'] = Request::post('status');
		$input['updater'] = Request::post('updater');
		$input['creater'] = Request::post('creater');
		$input['sort'] = Request::post('sort');
		$input['type_name'] = Request::post('type_name');
		$input['id'] = Request::post('id/d');

		// input结果返回
		$msg['data']['ext1'] = $input['ext1'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['sort'] = $input['sort'];
		$msg['data']['type_name'] = $input['type_name'];
		$msg['data']['id'] = $input['id'];

		// ---  模块 - 删除  ---
		//删除的条件
		$temp_map = [
			['ext1','=',$input['ext1']],
			['status','=',$input['status']],
			['updater','=',$input['updater']],
			['creater','=',$input['creater']],
			['sort','=',$input['sort']],
			['type_name','=',$input['type_name']],
			['id','=',$input['id']],
		];
		$delete_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2] == null || $v[2] == ''){
				continue;
			}
			array_push($delete_map,$v);
		}
		if(empty($delete_map)){
			$msg['msg'] = '删除条件不能为空';
			return $this->errorJson($msg);
		}

		//删除数据
		$delete_res = Db::name('category')->where($delete_map)->delete();
		if(!$delete_res){
			$msg['msg'] = '删除数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $delete_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取单条数据
	* @description 根据ID获取图片分类表的指定记录
	* @author 开发者（zzz）
	* @url /banner/category/info
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	*
	* @return id:id
	*
	*/
	public function info (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::param('id/d');

		// input结果返回
		$msg['data']['id'] = $input['id'];

		//模块 - 验证器
		$categoryValidate = new \app\banner\validate\Category;
		$validate = $categoryValidate->scene('only_id')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $categoryValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
		];
		//去除为空的条件
		$find_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($find_map,$v);
		}

		//获取数据
		$select_res = Db::name('category')->where($find_map)->find();

		// find 返回数据
		$msg['data'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 更新记录
	* @description 根据ID更新图片分类表指定记录的数据
	* @author 开发者（zzz）
	* @url /banner/category/edit
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预留字段1
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前状态
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:sort type:VarChar require:1 default:0 other: desc:排序值
	* @param name:type_name type:VarChar require:1 default:0 other: desc:分类名
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	*
	* @return ext1:预留字段1
	* @return status:当前状态
	* @return updater:更新者
	* @return creater:创建者
	* @return sort:排序值
	* @return type_name:分类名
	* @return id:id
	*
	*/
	public function edit (){
		$input=input();
		//模块 - 输入数据
		$input['ext1'] = Request::post('ext1');
		$input['status'] = Request::post('status');
		$input['updater'] = Request::post('updater');
		$input['creater'] = Request::post('creater');
		$input['sort'] = Request::post('sort');
		$input['type_name'] = Request::post('type_name');
		$input['id'] = Request::post('id/d');

		// input结果返回
		$msg['data']['ext1'] = $input['ext1'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['sort'] = $input['sort'];
		$msg['data']['type_name'] = $input['type_name'];
		$msg['data']['id'] = $input['id'];

		//模块 - 验证器
		$categoryValidate = new \app\banner\validate\Category;
		$validate = $categoryValidate->scene('update')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $categoryValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 修改  ---
		//更新的条件
		$update_date = [
		'id'=>$input['id'],
		];
		//更新的数据
		$update_map = [
			'ext1'=>$input['ext1'],
			'status'=>$input['status'],
			'updater'=>$input['updater'],
			'creater'=>$input['creater'],
			'sort'=>$input['sort'],
			'type_name'=>$input['type_name'],
		];
		//获取数据
		$update_res = Db::name('category')->where($update_date)->update($update_map);
		if(!$update_res){
			$msg['msg'] = '更新据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $update_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 插入记录
	* @description 插入图片分类表数据
	* @author 开发者（zzz）
	* @url /banner/category/add
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预留字段1
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前状态
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:sort type:VarChar require:1 default:0 other: desc:排序值
	* @param name:type_name type:VarChar require:1 default:0 other: desc:分类名
	*
	*
	* @return ext1:预留字段1
	* @return status:当前状态
	* @return updater:更新者
	* @return creater:创建者
	* @return sort:排序值
	* @return type_name:分类名
	*
	*/
	public function add (){
		$input=input();
		//模块 - 输入数据
		$input['ext1'] = Request::post('ext1');
		$input['status'] = '1';
		$input['updater'] = Request::post('updater');
		$input['creater'] = Request::post('creater');
		$input['sort'] = Request::post('sort');
		$input['type_name'] = Request::post('type_name');

		// input结果返回
		$msg['data']['ext1'] = $input['ext1'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['sort'] = $input['sort'];
		$msg['data']['type_name'] = $input['type_name'];

		//模块 - 验证器
		$categoryValidate = new \app\banner\validate\Category;
		$validate = $categoryValidate->scene('add')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $categoryValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 新增  ---
		//插入的数据
		$insert_data = [
			'ext1'=>$input['ext1'],
			'status'=>$input['status'],
			'updater'=>$input['updater'],
			'creater'=>$input['creater'],
			'sort'=>$input['sort'],
			'type_name'=>$input['type_name'],
		];
		//添加数据
		$insert_res = Db::name('category')->data($insert_data)->insert();
		if(!$insert_res){
			$msg['msg'] = '插入数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $insert_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（paginate）
	* @description 获取图片分类表的列表数据（分页）
	* @author 开发者（zzz）
	* @url /banner/category/get_list
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预留字段1
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前状态
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:sort type:VarChar require:1 default:0 other: desc:排序值
	* @param name:type_name type:VarChar require:1 default:0 other: desc:分类名
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	* @param name:page type:Int require:0 default:0 other: desc:当前页
	* @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
	*
	* @return ext1:预留字段1
	* @return status:当前状态
	* @return updater:更新者
	* @return creater:创建者
	* @return sort:排序值
	* @return type_name:分类名
	* @return id:id
	*
	*/
	public function get_list (){
		$input=input();
		//模块 - 输入数据
		$input['ext1'] = Request::param('ext1');
		$input['status'] = Request::param('status');
		$input['updater'] = Request::param('updater');
		$input['creater'] = Request::param('creater');
		$input['sort'] = Request::param('sort');
		$input['type_name'] = Request::param('type_name');
		$input['id'] = Request::param('id/d');

		// input结果返回
		$msg['data']['ext1'] = $input['ext1'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['sort'] = $input['sort'];
		$msg['data']['type_name'] = $input['type_name'];
		$msg['data']['id'] = $input['id'];

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['ext1','like','%'.$input['ext1'].'%'],
			['status','=',$input['status']],
			['updater','like','%'.$input['updater'].'%'],
			['creater','like','%'.$input['creater'].'%'],
			['sort','like','%'.$input['sort'].'%'],
			['type_name','like','%'.$input['type_name'].'%'],
			['id','=',$input['id']],
		];
		//去除为空的条件
		$paginate_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
                if($v[0] == 'status' && $v[2] ===0){
                    array_push($paginate_map,$v);
                }
				continue;
			}
			array_push($paginate_map,$v);
		}

		//获取数据
		$select_res = Db::name('category')->where($paginate_map)->paginate();

		// paginate 返回数据
		$msg['list'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
    /**
     * @title 获取列表数据（paginate）
     * @description 获取图片分类表的列表数据通过排序值排序（分页）
     * @author 开发者（zzz）
     * @url /banner/category/get_list_order_by_sort
     * @method *
     *
     * @param name:token require:1 default: desc:token
     *
     * @param name:ext1 type:VarChar require:1 default:0 other: desc:预留字段1
     * @param name:status type:TinyInt require:1 default:0 other: desc:当前状态
     * @param name:updater type:VarChar require:1 default:0 other: desc:更新者
     * @param name:creater type:VarChar require:1 default:0 other: desc:创建者
     * @param name:sort type:VarChar require:1 default:0 other: desc:排序值
     * @param name:type_name type:VarChar require:1 default:0 other: desc:分类名
     * @param name:id type:Int require:1 default:0 other: desc:id
     *
     * @param name:page type:Int require:0 default:0 other: desc:当前页
     * @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
     *
     * @return ext1:预留字段1
     * @return status:当前状态
     * @return updater:更新者
     * @return creater:创建者
     * @return sort:排序值
     * @return type_name:分类名
     * @return id:id
     *
     */
    public function get_list_order_by_sort (){
        $input=input();
        //模块 - 输入数据
        $input['ext1'] = Request::param('ext1');
        $input['status'] = Request::param('status');
        $input['updater'] = Request::param('updater');
        $input['creater'] = Request::param('creater');
        $input['sort'] = Request::param('sort');
        $input['type_name'] = Request::param('type_name');
        $input['id'] = Request::param('id/d');

        // input结果返回
        $msg['data']['ext1'] = $input['ext1'];
        $msg['data']['status'] = $input['status'];
        $msg['data']['updater'] = $input['updater'];
        $msg['data']['creater'] = $input['creater'];
        $msg['data']['sort'] = $input['sort'];
        $msg['data']['type_name'] = $input['type_name'];
        $msg['data']['id'] = $input['id'];

        // ---	模块 - 查询  ---
        //查询条件
        $temp_map = [
            ['ext1','like','%'.$input['ext1'].'%'],
            ['status','=',$input['status']],
            ['updater','like','%'.$input['updater'].'%'],
            ['creater','like','%'.$input['creater'].'%'],
            ['sort','like','%'.$input['sort'].'%'],
            ['type_name','like','%'.$input['type_name'].'%'],
            ['id','=',$input['id']],
        ];
        //去除为空的条件
        $paginate_map = [];
        foreach ($temp_map as $k=>$v){
            if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
                if($v[0] == 'status' && $v[2] === 0){
                    array_push($paginate_map,$v);
                }
                continue;
            }
            array_push($paginate_map,$v);
        }

        //获取数据
        $select_res = Db::name('category')->where($paginate_map)->order('sort','asc')->paginate();

        // paginate 返回数据
        $msg['list'] = $select_res;


        //接口输出json数据
        $msg['msg'] = '操作成功！';
        return $this->successJson($msg);
    }
	/**
	* @title 获取列表数据（select）
	* @description 获取图片分类表的列表数据（无分页）
	* @author 开发者（zzz）
	* @url /banner/category/get_select
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预留字段1
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前状态
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:sort type:VarChar require:1 default:0 other: desc:排序值
	* @param name:type_name type:VarChar require:1 default:0 other: desc:分类名
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	*
	* @return ext1:预留字段1
	* @return status:当前状态
	* @return updater:更新者
	* @return creater:创建者
	* @return sort:排序值
	* @return type_name:分类名
	* @return id:id
	*
	*/
	public function get_select (){
		$input=input();
		//模块 - 输入数据
		$input['ext1'] = Request::param('ext1');
		$input['status'] = Request::param('status');
		$input['updater'] = Request::param('updater');
		$input['creater'] = Request::param('creater');
		$input['sort'] = Request::param('sort');
		$input['type_name'] = Request::param('type_name');
		$input['id'] = Request::param('id/d');

		// input结果返回
		$msg['data']['ext1'] = $input['ext1'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['sort'] = $input['sort'];
		$msg['data']['type_name'] = $input['type_name'];
		$msg['data']['id'] = $input['id'];

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['ext1','like','%'.$input['ext1'].'%'],
			['status','=',$input['status']],
			['updater','like','%'.$input['updater'].'%'],
			['creater','like','%'.$input['creater'].'%'],
			['sort','like','%'.$input['sort'].'%'],
			['type_name','like','%'.$input['type_name'].'%'],
			['id','=',$input['id']],
		];
		//去除为空的条件
		$select_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($select_map,$v);
		}

		//获取数据
		$select_res = Db::name('category')->where($select_map)->select();

		// select 返回数据
		$msg['list'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}

}
